<?php 
Class articleController extends appController
{
	
	public function index()
	{
		$page=isset($_REQUEST['page'])?intval($_REQUEST['page']):1;
	
		$cache_id = $page. '-' .$_GET['code'] . '-' . DEFAULT_LANG. '-' .session('user_id');;
		
		$cache_id = sprintf('%X', crc32($cache_id));
		if (!$this->is_cached('list.html', $cache_id))
		{
			$app=Model('app');
			if(!$id=$app->code_to_id($_GET['code']))
			{
				hy_404();
			}
			$art=Model('article');
			$cat=$app->getCurClass($id);
			$this->assign('cat',$cat);
			$config[c]=array('site_name'=>$cat['name'].'-'.$app->get_cfg('site_name'));
			$this->assign_global($config);
			$art_list=$art->get_art_list($page,$id,4,$cfg);
		$this->assign('art_list',$art_list['data']);
		$this->assign('art_page',$art_list['pagelink']);
		
		}
		
		$this->display('list.html',$cache_id);
		
	}
	public function photo()
	{
		$page=isset($_REQUEST['page'])?intval($_REQUEST['page']):1;
	
		$cache_id = $page. '-' .$_GET['code'] . '-' . DEFAULT_LANG. '-' .session('user_id');;
	
		$cache_id = sprintf('%X', crc32($cache_id));
		if (!$this->is_cached('list.html', $cache_id))
		{
			$app=Model('app');
			if(!$id=$app->code_to_id($_GET['code']))
			{
				hy_404();
			}
			$art=Model('article');
			$cat=$app->getCurClass($id);
			$this->assign('cat',$cat);
			$config[c]=array('site_name'=>$cat['name'].'-'.$app->get_cfg('site_name'));
			$this->assign_global($config);
			$art_list=$art->get_art_list($page,$id,8,$cfg);
			$this->assign('art_list',$art_list['data']);
			$this->assign('art_page',$art_list['pagelink']);
	
		}
	
		$this->display('photo_list.html',$cache_id);
	
	}
	public function ajax_content()
	{
		$id=intval($_POST['id']);
		$result=array('error'=>1,'content'=>'');
		$page=Model('article')->get_art($id);
		
		if($page)
		{
			$result['error']=0;
		
			$result['content']='<img src="/Home/Webroot/default/images/t_29.jpg" />'.str_replace('<br />','<br /><img src="/Home/Webroot/default/images/t_29.jpg" />',$page['content']);
			if(strrpos($page['content'],'<br />')&&strlen($page['content'])-6==strrpos($page['content'],'<br />'))
			{
				$result['content']=substr($result['content'],0,strlen($result['content'])-51);
			}
		}
		die(json_encode($result));
	}
	public function page()
	{
		
		$cache_id = $_GET['code'] . '-' . DEFAULT_LANG. '-' .session('user_id');
		$cache_id = sprintf('%X', crc32($cache_id));
		if (!$this->is_cached('page.html', $cache_id))
		{
			$app=Model('app');
			if(!$id=$app->code_to_id($_GET['code']))
			{
				hy_404();
			}
			
			$photo_id=$app->code_to_id($_GET['code']);
			$cat_list=$app->getCurClass($photo_id);
			$this->assign('cat',$cat_list);
				
			$config[c]=array('site_name'=>$cat_list['name'].'-'.$app->get_cfg('site_name'));
			$this->assign_global($config);
			
			$page=Model('article')->get_single_page($id);
			if($page['form_id'])
			{
				Model('forms')->get_form($page['form_id']);
			}
			
			$this->assign('art',$page);
		}
		$this->display('page.html',$cache_id);
	}
	
	public function view()
	{
		$id=isset($_GET['id'])?intval($_GET['id']):'';
		$cache_id = $id . '-' . DEFAULT_LANG. '-' .session('user_id');;
		$art=Model('article');
		$art_cat=$art->article_cat($id);
		$art->art_click($id);
		$cache_id = sprintf('%X', crc32($cache_id));
		if (!$this->is_cached($art_cat['code'].'_view.html', $cache_id))
		{
		
		//$cat_id=Model('article')->article_cat($id);
		
		$art_info=$art->get_art($id);
		
		if(in_array($art_cat['code'],array('videaappreciation','showvideo','mediareport')))
		{
			$art_list=Model('article')->get_art_list(1,$art_cat['cat_id']);
			$this->assign('art_list',$art_list['data']);
		
		}
		$app=Model('app');
		$config[c]=array('site_name'=>$art_info['title'].'-'.$app->get_cfg('site_name'));
		$this->assign_global($config);
		$this->assign('art_page',$art->get_pn_page($id));
		$this->assign('art_cat',$art_cat);
		$this->assign('art',$art_info);
		
		}
		if($art_cat['code']=='')
		{
			$art_cat['code']='activities';
		}
		
		$this->display($art_cat['code'].'_view.html', $cache_id);
	}

	
	

	
	
}